//
//  mVSecendActiView.m
//  testCocoPods1.0
//
//  Created by ChenJs92 on 16/11/15.
//  Copyright © 2016年 chenjs92. All rights reserved.
//

#import "mVSecendActiView.h"
#import "MVSecendScrooViewMode.h"
#import "MVSecendScrooViewDataModel.h"
@interface mVSecendActiView()

@property(strong, nonatomic) MVSecendScrooViewMode *viewModel;
@property(strong, nonatomic) UIView *mainView;

@end

@implementation mVSecendActiView

-(instancetype)initWithViewModel:(id<MVViewModelProtocol>)viewModel{
    self.viewModel = (MVSecendScrooViewMode *)viewModel;
    return [super initWithViewModel:viewModel];
}
-(void)updateConstraints{
    WS(weakSelf)
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(weakSelf);
    }];
    [super updateConstraints];
}
#pragma mark - private
- (void)yd_setupViews {
    
    [self addSubview:self.mainView];
    [self setNeedsUpdateConstraints];
    [self updateConstraintsIfNeeded];
}
-(void)yd_bindViewModel{
    
    [self setActiList];
}
-(void)setActiList{
     NSLog(@"绘制actiView----------");
    NSArray *actiList = self.viewModel.actiList;
    UIScreen *wind = [UIScreen mainScreen];
    
    CGFloat btnWidth = wind.bounds.size.width/4.;
    for (int i=0; i<actiList.count; i++) {
        MVSecendScrooViewDataModel *model = (MVSecendScrooViewDataModel *)actiList[i];
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(i%4*btnWidth, i/4*40, btnWidth, 40)];
        [btn setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];
        [btn setTitle:model.titleName forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(touActiAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
    }
}
-(void)touActiAction:(UIButton *)sender{
//    [self.viewModel.cellClickSubject sendNext:nil];
    [self.viewModel.actiClickSubject sendNext:sender];
}
-(MVSecendScrooViewMode *)viewModel{
    if (!_viewModel) {
        _viewModel = [[MVSecendScrooViewMode alloc] init];
    }
    return _viewModel;
}
-(UIView *)mainView{
    if (!_mainView) {
        _mainView = [[UIView alloc] init];
        _mainView.backgroundColor = [UIColor blackColor];
    }
    return _mainView;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
